package com.example.liaotian.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;

import com.example.liaotian.R;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import cn.bmob.v3.Bmob;

/**
 * 主页面
 */

public class MainActivity extends AppCompatActivity {


    private NavController controller;
    /**
     * 2.12早上提交
     * @param savedInstanceState
     */


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //初始化Bmob
        Bmob.initialize(this,"320a371a14fd5a1f1820feeeeb04e264");
        initView();
    }



    /**
     *组件的绑定及装配的方法
     */
    private void initView() {
        BottomNavigationView bottomNavigationView = findViewById(R.id.bottomNavigationView);
        NavController navController = Navigation.findNavController(this,R.id.fragment3);
        //获取顶部标题栏的显示，这里获取了底部菜单的menu
        AppBarConfiguration configuration = new AppBarConfiguration.Builder(bottomNavigationView.getMenu()).build();
        //装配顶部UI显示
        NavigationUI.setupActionBarWithNavController(this,navController,configuration);
        //装配页面UI
        NavigationUI.setupWithNavController(bottomNavigationView,navController);

    }
    static {
        AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    }
    /**
     *
     *主页面按返回键会弹出提示框，是否退出程序
     */
    @Override
    public void onBackPressed() {
        new AlertDialog.Builder(MainActivity.this).setTitle("信息提示")//设置对话框标题

                .setMessage("是否退出社区？")
                .setPositiveButton("是", new DialogInterface.OnClickListener() {//添加确定按钮

                    @Override
                    public void onClick(DialogInterface dialog, int which) {//确定按钮的响应事件
                            finish();
                    }
                }).setNegativeButton("否", new DialogInterface.OnClickListener() {//添加返回按钮

            @Override
            public void onClick(DialogInterface dialog, int which) {//响应事件

            }

        }).show();//在按键响应事件中显示此对话框
    }





    }
